package com.example.pages;

import org.openqa.selenium.WebElement;
import org.openqa.selenium.support.FindBy;

public class LoginPage extends AnyPage {

	@FindBy(xpath = "html/body/div/div/div/section")
	public WebElement loginForm;

	@FindBy(xpath = "html/body/div[1]/div/div/section/div/form/table/tbody/tr[1]/td[2]/input")
	public WebElement userNameField;

	@FindBy(xpath = "html/body/div[1]/div/div/section/div/form/table/tbody/tr[2]/td[2]/input")
	public WebElement passwordField;

	@FindBy(xpath = "html/body/div[1]/div/div/section/div/form/table/tbody/tr[3]/td[2]/input")
	public WebElement loginButton;

	public boolean isOnThisPage() {
		return loginForm.isDisplayed();
	}

	@Override
	void tryToOpen() {
		MyPageFactory.getPage(driver, InternalPage.class).logOut();

	}

	public InternalPage loginWithValidCredentials(String userName,
			String password) {
		userNameField.sendKeys(userName);
		passwordField.sendKeys(password);
		loginButton.click();
		return MyPageFactory.getPage(driver, InternalPage.class);
	}

	public LoginPage loginWithWrongCredentials(String userName, String password) {
		userNameField.sendKeys(userName);
		passwordField.sendKeys(password);
		loginButton.click();
		return MyPageFactory.getPage(driver, LoginPage.class);
	}

}
